import java.util.Scanner;

/* Author: Andrew Shore
 * CSCE 145 Section 004
 * 
 */
public class CDCatalog {
	

		static CD[] cdArray;
		private String nameOfCatalog;
		public static final int DEFAULT_SIZE=10;
		
		public CDCatalog(){
			
			cdArray=new CD[DEFAULT_SIZE];
			nameOfCatalog="Unknown";
			
		}
		
		public CDCatalog(String name){
			nameOfCatalog=name;
			cdArray=new CD[DEFAULT_SIZE];
			
		}
		
		//accesssors
		public String getName(){
			return nameOfCatalog;
		}
		//mutators
		public void setName(String newName){
			nameOfCatalog=newName;
		}
		public static void addCD(CD aCD){
			for(int index=0; index< cdArray.length; index++){
				if(cdArray[index] == null){
					cdArray[index] = aCD;
					return;
				}
			}

		}
		
		public static void removeCD(CD aCD){
			
			
			for(int index=0; index<cdArray.length; index++){
				
				if(cdArray[index].getTitle().equals(aCD.getTitle()) && cdArray[index].getArtist().equals(aCD.getArtist())&& cdArray[index].getRecordLabel().equals(aCD.getRecordLabel())){
					
					cdArray[index]=null;
					return;
					
				}
			}
		}
		public static int countCD(){
			int counter=0;
			for(int index=0; index<cdArray.length; index++){
				
			
				if(cdArray[index]!=null){
					counter++;
					
				}
				
			}
			return counter;
		}
		public static void showAll(){
			for(int index=0; index<cdArray.length; index++){
				if(cdArray[index]!=null){
				System.out.println(cdArray[index].getTitle()+", "+cdArray[index].getArtist()+", "+cdArray[index].getRecordLabel());
				}
				else{
					return;
				}
				if(cdArray[index]==null){
					System.out.println("Your catalog is empty.");
					return;
				}
				
			}
		}
	

	/**
	 * @param args
	 */
	
	

public static void main(String[] args) {
	// TODO Auto-generated method stub
	Scanner keyboard=new Scanner(System.in);
	
	System.out.println("Welcome to the CD catalog. Please give a name for your catalog:");
		String name=keyboard.nextLine();
		CDCatalog myCatalog=new CDCatalog(name);
		boolean isContinue= true;

	while(isContinue){
		
		System.out.println("Select an option for "+name+": Type \"add\" to add, \"remove\" to remove, \"show all\" to display the contents of the CD catalog," +
				 " \"count\" to determine the number of CDs in the CDCatalog, or \"quit\" to quit:");
		String answer=keyboard.nextLine();
		
		if(answer.equalsIgnoreCase("add")){
			System.out.println("Enter information to add");
			
			System.out.println("Artist:");
			String artist=keyboard.nextLine();
			
			System.out.println("Title:");
			String title=keyboard.nextLine();
			
			System.out.println("Label:");
			String label=keyboard.nextLine();
			
			CD newCD=new CD(artist, title, label);
			CDCatalog.addCD(newCD);
		}
		if(answer.equalsIgnoreCase("remove")){
System.out.println("Enter information to remove");
			
			System.out.println("Artist:");
			String artist=keyboard.nextLine();
			
			System.out.println("Title:");
			String title=keyboard.nextLine();
			
			System.out.println("Label:");
			String label=keyboard.nextLine();
			CD newCD=new CD(artist, title, label);
			
			CDCatalog.removeCD(newCD);
		}
		if(answer.equalsIgnoreCase("count")){
			System.out.println("You have "+CDCatalog.countCD()+" in your catalog");
		}
		if(answer.equalsIgnoreCase("show all")){
			System.out.println("The contents of your catalog are:");
			CDCatalog.showAll();
		}
		if(answer.equalsIgnoreCase("quit")){
			isContinue=false;
		}
		
	}
	
}
}

